using System;
using System.Collections.Generic;
using GameFramework;
using GameFramework.Fsm;
using StarForce.Manager;

namespace StarForce
{
    /// <summary>
    /// 准备阶段
    /// </summary>
    public class EliminateReadFSM : EliminateFSM
    {


        private bool m_Start;
        
        protected override void OnEnter(IFsm<EliminateGame> fsm)
        {
            base.OnEnter(fsm);
            //打开主UI
            GameEntry.UI.OpenUIForm(UIFormId.EliminateMainPage, this);

            GameEntry.Eliminate.SetListLength(Constant.EliminateGameConfig.HCount*Constant.EliminateGameConfig.VCount);

            CreateItem();
            CheckAll();
        }

        protected override void OnUpdate(IFsm<EliminateGame> fsm, float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(fsm, elapseSeconds, realElapseSeconds);
            if (m_Start)
            {
                ChangeState<EliminateStartFSM>(fsm);   
            }
        }

        protected override void OnLeave(IFsm<EliminateGame> fsm, bool isShutdown)
        {
            base.OnLeave(fsm, isShutdown);
            m_Start = false;
        }

        /// <summary>
        /// 生成方块
        /// </summary>
        private void CreateItem()
        {
            for (int i = 0; i < Constant.EliminateGameConfig.HCount* Constant.EliminateGameConfig.VCount; i++)
            {
                GameEntry.Eliminate.Show(EliminateGameUtility.GetRandomData(i));
            }
            
        }

        /// <summary>
        /// 检查所有方块能否消除
        /// </summary>
        private void CheckAll()
        {
            EliminateInspectManager.Instance.CheckAll();

            m_Start = true;
        }

    }
}